#include "GunWeapon.h"
#include "RSManager.h"
#include "Box.h"
#include "Sprite.h"
#include "ShareComponents.h"
#include "Camera.h"
//GunWeapon::GunWeapon(Box* box, SPRITE_ID weadpon_id): Object(box, ObjEnemy_DYNAMID)
GunWeapon::GunWeapon(Box* box, BULLET_ID weadpon_id): Object(box, DEBUG_GAME)
{
	_weapon_id=weadpon_id;
	_initpos=box->_position;
}


GunWeapon::~GunWeapon(void)
{
}
void GunWeapon::init()
{
	switch(_weapon_id)
	{
	case B_M: _sprite= RSManager::getInstance()->getSprite(MACHINE_GUN);break;
	case B_S: _sprite= RSManager::getInstance()->getSprite(SPREAD_GUN);break;
	case B_F:_sprite =RSManager::getInstance()->getSprite(FIREBALL_GUN);break;
	case B_L:_sprite=RSManager:: getInstance()->getSprite(LASER);break;
	case B_R:_sprite=RSManager::getInstance()->getSprite(RAPID_UPDATE);break;
	case B_B: _sprite= RSManager::getInstance()->getSprite(BARRIER);break;
	case B_D: _sprite =RSManager::getInstance()->getSprite(	A_BOMB);break;
	}
	_hits=1;
	delay =0;
	_isAlive=true;
	AssignMove(_box);
	_box->_v.x = 0;
	_box->_v.y = 0;

}
void GunWeapon::update()
{
	delay+=GAME_TIME;
	if(_box->_position.y>gl_camera->getRightSide()-50)
	{
		if(isOnSpace())
		{
			_box->_v.x = -2;
			if(_box->_v.y == 0)
			{
				_box->_v.y = 8;
			}
		}
	}

	else
	{
		if(isOnSpace())
		{
			_box->_v.x = 2;
						if(_box->_v.y == 0)
			{
				_box->_v.y = 8;
			}
		}
	};
	if(_weapon_id==B_D && delay>100) 
	{
		delay=0;
		_sprite->Next();
	}

	//if(_hits<=0) _isAlive=false;
	if(isOnSpace())
		move();
}
void GunWeapon::render()
{
	if(_isAlive)
		_sprite->Render(_box->_position);
}
Box* GunWeapon:: getCollisionBox()
{
	_colBox->_position=_box->_position;
	_colBox->_size=_box->_size;
	_colBox->_v =_box->_v;
	return _colBox;
}